<?php
/**
 * Created by PhpStorm.
 * User: YongX
 * Date: 2017/2/13
 * Time: 14:05
 */

namespace App\other\Notification;


use App\models\forum\Replie;
use App\models\user\EmailToken;
use App\models\user\User;
use App\other\TokenType;
use App\other\UtilsClass;
use Illuminate\Mail\Message;
use Mail;

class SendMail
{
    public static function sendRegisterEmail(User $user){
        EmailToken::deleteToken($user->id, TokenType::TOKEN_PASSWDRESET_TYPE);
        $token              = EmailToken::where('uid', $user->id)->first();
        if (empty($token)){
            $token          = new EmailToken();
        }
        $token->uid         = $user->id;
        $token->type        = TokenType::TOKEN_REGISTER_TYPE;
        $token->token       = UtilsClass::getRandomStringCode(32);
        $token->dead_time   = time()+60*30;
        $token->save();
        $data = ['email' => $user->email, 'name'=>env('MAIL_NAME', 'MeShop'), 'token'=>$token->token , 'id'=>$token->id, 'username'=>$user->name];
        Mail::send('mail.email', $data, function(Message $message) use($data) {
            $message->to($data['email'], $data['username'])->subject('请激活您的账号！');
        });
    }

    public static function sendReplyNotify(User $user, Replie $replie, $listUser){
        $notyfier = new Notifier();
        $notyfier->newReplyNotify($user, $listUser, $replie);
    }
}